/**
 * 
 */
package com.lmm.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

/**
 * @author leiming
 *
 */
public class ContentUtils {

	/**
	 * 获取参数字符串
	 * @return
	 */
	private static List<String> readParameters(InputStream in){
		 //InputStream in = TestLogin.class.getResourceAsStream("content.txt");
		 List<String> listStr = null;
		 try {
			 listStr = IOUtils.readLines(in);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			IOUtils.closeQuietly(in);
		}
		 return listStr;
	}
	/**
	 * 获取参数
	 * @param listStr
	 * @return
	 */
	public static List<NameValuePair> gerneretNameValuePair(InputStream in){
		List<String> listStr = readParameters(in);
		List<NameValuePair> listParameter = new ArrayList<NameValuePair>();
    	for(String str:listStr){
    		String[] tmp = str.split(":");
    		if(tmp.length==1){
    			listParameter.add(new BasicNameValuePair(tmp[0], ""));
    		}else{
    			listParameter.add(new BasicNameValuePair(tmp[0], tmp[1]));
    		}
    		
    	}
    	return listParameter;
	}
}
